package subject_set.offer100;

/**
 * @author haomin
 * @date 2022/10/13 22:09
 **/
public class Offer15 {
    public class Solution {
        // you need to treat n as an unsigned value
        public int hammingWeight(int n) {
            int ans = 0;
            int m = 32;
            while(m-- > 0){
                ans += (n & 1);
                n >>= 1;
            }
            return ans;
        }
    }
}